package com.ruoyi.customerService.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskReturnUpdateVo;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskReturnVo;
import com.ruoyi.customerService.domain.vo.CsCollaborativeTaskVo;
import com.ruoyi.customerService.domain.vo.CsTaskCollectVo;
import com.ruoyi.customerService.enums.TaskStatusEnum;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.customerService.domain.CsCollaborativeTask;
import com.ruoyi.customerService.service.ICsCollaborativeTaskService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * taskController
 *
 * @author pyx
 * @date 2024-01-29
 */
@RestController
@RequestMapping("/cs/collaborativeTask")
@Api(tags = "客服中心-协作任务管理")
public class CsCollaborativeTaskController extends BaseController{

    @Autowired
    private ICsCollaborativeTaskService csCollaborativeTaskService;
    /**
     * 查询task列表
     */
    @ApiOperation("列表")
    @PostMapping("/selectAll")
    @ResponseBody
    public R selectAll(CsCollaborativeTaskVo csCollaborativeTaskVo)
    {
        List<CsCollaborativeTask> list = csCollaborativeTaskService.selectCsCollaborativeTaskList(csCollaborativeTaskVo);

        return R.ok(PageInfo.info(list));
    }

    /**
     * 我发起的列表
     */
    @ApiOperation("协作任务分页列表")
    @PostMapping("/selectList")
    @ResponseBody
    public R selectList(@RequestBody CsCollaborativeTaskVo csCollaborativeTaskVo)
    {
        List<CsCollaborativeTask> list = new ArrayList<>();
        if (csCollaborativeTaskVo.getCode().equals("selectMine")){
            csCollaborativeTaskVo.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
            list = csCollaborativeTaskService.selectCsCollaborativeTaskList(csCollaborativeTaskVo);
            for (CsCollaborativeTask csCollaborativeTask : list) {
                csCollaborativeTaskVo.setTaskStatus(TaskStatusEnum.getValue(csCollaborativeTask.getTaskStatus()));
            }
        }else if (csCollaborativeTaskVo.getCode().equals("selectSend")){
            csCollaborativeTaskVo.setStartNetworkNameId(SecurityUtils.getDeptId());
            list = csCollaborativeTaskService.selectCsCollaborativeTaskList(csCollaborativeTaskVo);
        }else if (csCollaborativeTaskVo.getCode().equals("selectGet")){
            csCollaborativeTaskVo.setProcessNetworkNameId(SecurityUtils.getUserId());
            list = csCollaborativeTaskService.selectCsCollaborativeTaskList(csCollaborativeTaskVo);
        }else {
            list = csCollaborativeTaskService.selectCsCollaborativeTaskList(csCollaborativeTaskVo);
        }
        return R.ok(PageInfo.info(list));
    }


    /**
     * 新增保存task
     */
    @ApiOperation("新增任务")
    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody CsCollaborativeTask csCollaborativeTask)
    {
        return csCollaborativeTaskService.insertCsCollaborativeTask(csCollaborativeTask);
    }

    /**
     * 批量回复
     */
    @ApiOperation("批量回复")
    @PostMapping("/returnContent")
    @ResponseBody
    public R returnContent(@RequestBody CsCollaborativeTaskReturnVo csCollaborativeTaskReturnVo)
    {
        return csCollaborativeTaskService.returnContent(csCollaborativeTaskReturnVo);
    }

    @ApiOperation("批量分配移交")
    @PostMapping("/updateList")
    @ResponseBody
    public R updateList(@RequestBody CsCollaborativeTaskReturnUpdateVo vo)
    {
        return csCollaborativeTaskService.updateList(vo);
    }

    /**
     * 批量收藏
     */
    @ApiOperation("批量收藏")
    @PostMapping("/collect")
    @ResponseBody
    public R collect(@RequestBody CsTaskCollectVo csTaskCollectVo)

    {
        return csCollaborativeTaskService.collect(csTaskCollectVo.getIds());
    }


    /**
     * 删除task
     */
    @ApiOperation( "删除")
    @PostMapping( "/remove")
    @ResponseBody
    public R remove(String ids)
    {
        return csCollaborativeTaskService.deleteCsCollaborativeTaskByIds(ids);
    }
}
